import Router from "vue-router";
import routes from "./routes";

export function createRouter(ssrContext, createDefaultRouter, routerOptions) {
    const options = routerOptions
        ? routerOptions
        : createDefaultRouter(ssrContext).options;

    return new Router({
        ...options,
        // 页面的基础必须包含的路由
        base: window.__POWERED_BY_QIANKUN__ ? "/nuxt" : "/",
        mode: "history",
        routes: fixRoutes(options.routes)
    });
}

function fixRoutes() {
    // default routes that come from `pages/`
    return [].concat(routes);
}
